import java.util.Arrays;

public class test {
    public static void main(String[] args) {
        int[] coins = new int[]{186,419,83,408};
        coinChange(coins, 6249);
    }

    public static int coinChange(int[] coins, int amount) {
        int[] dp = new int[amount+1];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        Arrays.sort(coins);
        for(int x : coins){
            for(int i = x; i <= amount; i++){
                dp[i] = dp[i-x] == -1 ? -1 : dp[i] == -1 ? dp[i-x]+1 : Math.min(dp[i], dp[i-x]+1);
            }
            System.out.println(Arrays.toString(dp));
        }
        return dp[amount];

    }
}
